<?php

namespace Modules\Admin\Http\Controllers\Ebooks;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Modules\Common\General\Security\Api\Gateway;
use Modules\Common\Models\AdminLog;
use Modules\Common\Models\Ebooks;
use Modules\Common\Util\Api;
use Modules\Common\Util\Database;


class Update
{

    /**
     *@Route(path=/api/admin/ebook  method=put)
    */
    public function index()
    {
        Api::validate(['id' => 'required|integer']);
        $id = request('id');
        $adminUserIdDefault = auth('api')->user()->id;
        $eidDefault = auth('api')->user()->eid; 
        $sidDefault = auth('api')->user()->sid;
        $ebooks = Ebooks::updateFromArray([
            'id' => $id,
            'book_name'=>request('book_name'),
            'sub_title'=>request('sub_title'),
            'author'=>request('author'),
            'author_id'=>request('author_id'),
            'assetsId'=>request('assetsId'),
            'url'=>request('url'),
            'isbn'=>request('isbn'),
            'category_id'=>request('category_id'),
            'publisher'=>request('publisher'),
            'publish_date'=>request('publish_date'),
            'language'=>request('language'),
            'page_count'=>request('page_count'),
            'price'=>request('price'),
            'underlined_price'=>request('underlined_price'),
            'format'=>request('format'),
            'content'=>request('content'),
            'description'=>request('description'),
            'available'=>request('available'),
            'is_free'=>request('is_free'),
            'is_recommend'=>request('is_recommend'),
            'free_chapter_count'=>request('free_chapter_count'),
            'total_chapter_count'=>request('total_chapter_count'),
            'total_sections_count'=>request('total_sections_count'),
            'cover_image_fileid'=>request('cover_image_fileid'),
            'cover_image'=>request('cover_image'),
            'is_published'=>request('is_published'),
            'ebook_fileid'=>request('ebook_fileid'),
            'admin_user_id'=>$adminUserIdDefault,
            'eid'=>$eidDefault,
            'sid'=>$sidDefault,
        ]);
        return Api::success($ebooks);
    }
}